#include <SDL/SDL_image.h>
#include "constantes.h"
#include "StartScreen.h"

using namespace SDL::UTILS;
using namespace SDL::ELEMENTS;

StartArgs::StartArgs(SDL_Surface* _screen, SDL_Event* _event) : MyScreenArgs(_screen, _event)
{
}

StartArgs::~StartArgs()
{
}



StartScreen::StartScreen() : IScreen(),
	m_pbOnePlayer(L"Solo")
{
	m_surface.SetSurface(IMG_Load(std::string(CST::BG_PATH + "start.png").c_str()));
	this->InitButtons();
}

StartScreen::~StartScreen()
{
}

void StartScreen::Draw(IArgs* _args)
{
	StartArgs* sa = dynamic_cast<StartArgs*>(_args);

	m_pbOnePlayer.Draw(m_surface.GetSurface());

	m_surface.BlitSurface(NULL, sa->Screen, NULL);
}

void StartScreen::Exec(IArgs* _args)
{
	m_pbOnePlayer.UpdateState();
}

bool StartScreen::Manage(SDL::UTILS::ScreenManager::Element* _caller, SDL::UTILS::IArgs* _args)
{
	StartScreen* ss = dynamic_cast<StartScreen*>(_caller->Object);

	if (ss->m_pbOnePlayer.GetState() == SDL::BUTTON::STATE::CLICKED)
		ss->On_pbOnePlayer_Clicked(_caller->Datas);
	return (true);
}

void StartScreen::InitButtons()
{
	Rect upperRight(0, 0, m_surface.GetW(), m_surface.GetH());
	Sint16 xbutton = upperRight.x + (upperRight.w / 2 - m_pbOnePlayer.GetDefaultSize().w / 2);
	Sint16 ybutton = 300;
	
	m_pbOnePlayer.SetPosition(xbutton, ybutton);
	ybutton += 48;
}

void StartScreen::On_pbOnePlayer_Clicked(SDL::UTILS::IArgs* _datas)
{
	StartArgs* sa = dynamic_cast<StartArgs*>(_datas);
	sa->Value = 1;
}
